#include "analysis.h"
#include "my_header.h"
#include "transfile.h"
//判断函数头并更新命令标记类型
int chooseCommand(const char* p,Canalysis_t* canalysis){
    
    /* printf("chooseCommand is %s\n",p); */
    
    int ret = -1;
    ret = strcmp(p,"cd");
    if(ret == 0){
        canalysis->flag = FLAG_CD;
        /* canalysis->offset = 3; */
        /* printf("cd success\n"); */
        return 0;
    }
    ret = strcmp(p,"ls");
    if(ret == 0){
        canalysis->flag = FLAG_LS;
        /* canalysis->offset = 3; */
        /* printf("ls success\n"); */
        return 0;
    }
    ret = strcmp(p,"pwd");
    if(ret == 0){
        canalysis->flag = FLAG_PWD;
        /* canalysis->offset = 4; */
        return 0;
    }
    ret = strcmp(p,"mkdir");
    if(ret == 0){
        canalysis->flag = FLAG_MKDIR;
        /* canalysis->offset = 6; */
        return 0;
    }
    ret = strcmp(p,"rmdir");
    if(ret == 0){
        canalysis->flag = FLAG_RMDIR;
        /* canalysis->offset = 6; */
        return 0;
    }
    ret = strcmp(p,"gets");
    if(ret == 0){
        canalysis->flag = FLAG_GETS;
        /* canalysis->offset = 6; */
        return 0;
    }
    ret = strcmp(p,"puts");
    if(ret == 0){
        canalysis->flag = FLAG_PUTS;
        /* canalysis->offset = 6; */
        return 0;
    }
    ret = strcmp(p,"remove");
    if(ret == 0){
        canalysis->flag = FLAG_REMOVE;
        /* canalysis->offset = 6; */
        return 0;
    }
    return -1;
}

//业务实现，传入已经完成的栈命令，传入传出结果
int cdDir(const char* finalPath,Canalysis_t* canalysis){
    DEBUG_PRINT("begin cdDir finalpath is %s\n",finalPath);
    bzero(canalysis->result,canalysis->resultLength);
    
    char cd[1024];
    bzero(cd,sizeof(cd));
    sprintf(cd,"select fid,path,type from file_table where username = '%s' and type = 'd' and path = '%s'",canalysis->username,finalPath);
    int qret = mysql_query(canalysis->mysql,cd);
    if(qret != 0){
        fprintf(stderr,"%s:%s\n","mysql_query",mysql_error(canalysis->mysql));
        DEBUG_PRINT("cdDir mysql_query failed\n");
        exit(-1);
    }
    MYSQL_RES* rows = mysql_store_result(canalysis->mysql);
    if(mysql_num_rows(rows) == 0){
        sprintf(canalysis->result,"cd 命令切换失败，无效的目录，当前目录为：%s",canalysis->nowPath);
        return -1;
    }
    MYSQL_ROW row = mysql_fetch_row(rows);
    canalysis->pwd = atoi(row[0]);
    sprintf(canalysis->nowPath,"%s",row[1]);
    sprintf(canalysis->result,"cd 命令切换成功，当前目录为：%s",canalysis->nowPath);

    mysql_free_result(rows);
    return 0;
}

int lsDir(const char* finalPath,Canalysis_t* canalysis){
    DEBUG_PRINT("begin lsDir finalpath is %s\n",finalPath);
    bzero(canalysis->result,canalysis->resultLength);
    
    char ls[1024];
    bzero(ls,sizeof(ls));
    sprintf(ls,"select fid,filename,type from file_table where username = '%s' and type = 'd' and parent_id = '%d'",
            canalysis->username,canalysis->pwd);
    int qret = mysql_query(canalysis->mysql,ls);
    if(qret != 0){
        fprintf(stderr,"%s:%s\n","mysql_query",mysql_error(canalysis->mysql));
        DEBUG_PRINT("lsDir mysql_query failed\n");
        exit(-1);
    }
    MYSQL_RES* rows = mysql_store_result(canalysis->mysql);
    unsigned long rowNumber = mysql_num_rows(rows);
    if(rowNumber == 0){
        sprintf(canalysis->result,"ls命令执行失败，无效的目录，当前目录为：%s",canalysis->nowPath);
        return -1;
    }

    for(unsigned long i = 0;i < mysql_num_rows(rows); i++){
        MYSQL_ROW row = mysql_fetch_row(rows);
        rowNumber--;
        if(i == 0){
            sprintf(canalysis->result,"%s",row[1]);
        }else{
            sprintf(canalysis->result,"%s %s",canalysis->result,row[1]);

        }
    }

    return 0;
}

int pwdDir(const char* finalPath,Canalysis_t* canalysis){
    DEBUG_PRINT("begin pwdDir finalpath is %s\n",finalPath);
    bzero(canalysis->result,canalysis->resultLength);

    char pwd[1024];
    sprintf(pwd,"select path from file_table where fid = %d",canalysis->pwd);
    int qret = mysql_query(canalysis->mysql,pwd);
    if(qret != 0){
        fprintf(stderr,"%s:%s\n","mysql_query",mysql_error(canalysis->mysql));
        DEBUG_PRINT("pwdDir mysql_query failed\n");
        exit(-1);
    }
    MYSQL_RES* rows = mysql_store_result(canalysis->mysql);
    unsigned long rowNumber = mysql_num_rows(rows);
    if(rowNumber == 0){
        sprintf(canalysis->result,"pwd命令执行失败，当前目录为：%s",canalysis->nowPath);
        return -1;
    }
    MYSQL_ROW row = mysql_fetch_row(rows);
    sprintf(canalysis->result,"%s",row[0]);

    mysql_free_result(rows);
    return 0;
}


int insertDirFile_table(Canalysis_t* canalysis){
    char insert[1024];
    bzero(insert,sizeof(insert));

    DEBUG_PRINT("before insert now lastname is %s\n",canalysis->lastname);
    
    char buffer[1024] = {0};
    DEBUG_PRINT("before insert now nowPath is %s\n",canalysis->nowPath);
    if(strcmp(canalysis->nowPath,"/") == 0){
        sprintf(buffer,"%s%s",canalysis->nowPath,canalysis->lastname);
    }
    else{
        sprintf(buffer,"%s/%s",canalysis->nowPath,canalysis->lastname);
    }
    bzero(canalysis->nowPath,canalysis->nowPathLength);
    sprintf(canalysis->nowPath,"%s",buffer);
    DEBUG_PRINT("before insert now path is %s\n",canalysis->nowPath);
    
    sprintf(insert,"insert into file_table (filename,username,parent_id,path,type) values ('%s','%s',%d,'%s','d')",
            canalysis->lastname,canalysis->username,canalysis->pwd,canalysis->nowPath);
    int qret = mysql_query(canalysis->mysql,insert);
    if(qret != 0){
        fprintf(stderr,"%s:%s\n","mysql_query",mysql_error(canalysis->mysql));
        DEBUG_PRINT("mkDir mysql_query failed\n");
        exit(-1);
    }

    DEBUG_PRINT("buffer is %s\n",buffer);
    int ret = cdDir(buffer,canalysis);
    DEBUG_PRINT("insert now pwd key is %d\n",canalysis->pwd);
    DEBUG_PRINT("insert now lastname is %s\n",canalysis->lastname);
    DEBUG_PRINT("insert now path is %s\n",canalysis->nowPath);
    if(ret == -1){
        return -1;
    }
    
    return 0;
}

int mkdir_p(const char* finalpath,Canalysis_t* canalysis){
    DEBUG_PRINT("begin mkdir_p  %s\n",canalysis->nowPath);
    DEBUG_PRINT("now filename is %s\n",canalysis->lastname);
    DEBUG_PRINT("now finalpath is %s\n",finalpath);
    
    if(cdDir(finalpath,canalysis) == 0){
        return 0;
    }

    char temp[1024];
    bzero(temp,sizeof(temp));

    sprintf(temp,"%s",finalpath);
    DEBUG_PRINT("now temp is %s\n",temp);
    char* lastnameBuffer = strrchr(temp,'/');
   
    DEBUG_PRINT("lastnameBuffer is %s\n",lastnameBuffer);

    if(lastnameBuffer - temp == 0){
        DEBUG_PRINT("null lastnameBuffer\n");
        sprintf(canalysis->lastname,"%s",lastnameBuffer+1);
        DEBUG_PRINT("canalysis lastname is %s\n",canalysis->lastname);

        return insertDirFile_table(canalysis);
    }

    *lastnameBuffer = '\0';
    
    const char* dirname = lastnameBuffer + 1;
    DEBUG_PRINT("dirname is %s\n",dirname);
    
    if(strlen(temp) == 0){
        sprintf(temp,"/");
    }
    
    if(mkdir_p(temp,canalysis)!=0){
        return -1;
    } 
    
    sprintf(canalysis->lastname,"%s",dirname);
    return insertDirFile_table(canalysis);
}

int mkDir(const char* finalPath,Canalysis_t* canalysis){
    DEBUG_PRINT("begin mkDir finalpath is %s\n",finalPath);
    bzero(canalysis->result,canalysis->resultLength);
    
    char buffer[256] = {0};
    sprintf(buffer,"%s",canalysis->nowPath);

    DEBUG_PRINT("begin mkdir_p finalpath is %s\n",finalPath);
    int ret = mkdir_p(finalPath,canalysis);
    DEBUG_PRINT("after mkdir_p resultpath is %s\n",canalysis->nowPath);
    if(ret == -1){
        sprintf(canalysis->result,"创建文件夹失败，当前目录为%s",canalysis->nowPath);
        return -1;
    }
    cdDir(buffer,canalysis);
    sprintf(canalysis->result,"创建文件夹成功，当前目录为%s",canalysis->nowPath);
    return 0;
}

/* // 计算文件哈希值，结果存入sha1str中，需要41个字节 */
/* static int sha1_file(const char *filename, char *sha1str) { */
/*     EVP_MD_CTX *mdctx = EVP_MD_CTX_new(); */
/*     if (!mdctx) { */
/*         fprintf(stderr, "Error: EVP_MD_CTX_new failed\n"); */
/*         return 0; */
/*     } */

/*     // 初始化 SHA-1 哈希计算 */
/*     if (EVP_DigestInit_ex(mdctx, EVP_sha1(), NULL) != 1) { */
/*         fprintf(stderr, "Error: EVP_DigestInit_ex failed\n"); */
/*         EVP_MD_CTX_free(mdctx); */
/*         return 0; */
/*     } */

/*     int fd = open(filename, O_RDONLY); */
/*     if (fd == -1) { */
/*         perror("open"); */
/*         EVP_MD_CTX_free(mdctx); */
/*         return 0; */
/*     } */

/*     unsigned char buf[4096]; */
/*     while (1) { */
/*         ssize_t sret = read(fd, buf, sizeof(buf)); */
/*         if (sret == -1) { */
/*             perror("read"); */
/*             close(fd); */
/*             EVP_MD_CTX_free(mdctx); */
/*             return 0; */
/*         } */
/*         if (sret == 0) break;  // 文件读取完毕 */

/*         // 更新哈希计算 */
/*         if (EVP_DigestUpdate(mdctx, buf, sret) != 1) { */
/*             fprintf(stderr, "Error: EVP_DigestUpdate failed\n"); */
/*             close(fd); */
/*             EVP_MD_CTX_free(mdctx); */
/*             return 0; */
/*         } */
/*     } */
/*     close(fd); */

/*     unsigned char md[EVP_MAX_MD_SIZE]; */
/*     unsigned int md_len; */
/*     if (EVP_DigestFinal_ex(mdctx, md, &md_len) != 1) { */
/*         fprintf(stderr, "Error: EVP_DigestFinal_ex failed\n"); */
/*         EVP_MD_CTX_free(mdctx); */
/*         return 0; */
/*     } */
/*     EVP_MD_CTX_free(mdctx); */

/*     // 将二进制哈希值转换为十六进制字符串 */
/*     for (unsigned int i = 0; i < md_len; ++i) { */
/*         sprintf(sha1str + i * 2, "%02x", md[i]); */
/*     } */
/*     sha1str[md_len * 2] = '\0';  // 确保字符串以 '\0' 结尾 */

/*     return 1; */
/* } */

int rmDir(const char* finalPath,Canalysis_t* canalysis){
    DEBUG_PRINT("begin rmDir finalpath is %s\n",finalPath);
    bzero(canalysis->result,canalysis->resultLength);
    
    char rmdir_now[1024];
    bzero(rmdir_now,sizeof(rmdir_now));
    snprintf(rmdir_now,strlen(finalPath)-strlen(canalysis->lastname),"%s",finalPath);
    DEBUG_PRINT("rmdir correct is %s\n",rmdir_now);
    
    int ret = cdDir(rmdir_now,canalysis);
    if(ret == -1){
        return -1;
    }
    DEBUG_PRINT("rmdir now path is %s\n",canalysis->nowPath);
    
    cdDir(finalPath,canalysis);

    char rmdir[1024];
    bzero(rmdir,sizeof(rmdir));
    sprintf(rmdir,"select parent_id from file_table where username = '%s' and parent_id = %d",
            canalysis->username,canalysis->pwd);

    int qret = mysql_query(canalysis->mysql,rmdir);
    if(qret != 0){
        fprintf(stderr,"%s:%s\n","mysql_query",mysql_error(canalysis->mysql));
        DEBUG_PRINT("mkDir search mysql_query failed\n");
        exit(-1);
    }
    MYSQL_RES* rows = mysql_store_result(canalysis->mysql);
    unsigned long rowNumber = mysql_num_rows(rows);
    if(rowNumber != 0){
        sprintf(canalysis->result,"删除文件夹失败，文件夹非空，当前目录为%s",canalysis->nowPath);
        return -1;
    }
    
    DEBUG_PRINT("rowNumber is %lu\n",rowNumber);
    bzero(rmdir,sizeof(rmdir));
     
    sprintf(rmdir,"delete from file_table where username = '%s' and path = '%s'",canalysis->username,finalPath);
    qret = mysql_query(canalysis->mysql,rmdir);
    if(qret != 0){
        fprintf(stderr,"%s:%s\n","mysql_query",mysql_error(canalysis->mysql));
        DEBUG_PRINT("mkDir mysql_query failed\n");
        exit(-1);
    }
    char buffer[1024];
    bzero(buffer,sizeof(buffer));
    snprintf(buffer,strlen(canalysis->nowPath)-strlen(canalysis->lastname),"%s",canalysis->nowPath);
    cdDir(buffer,canalysis);
    sprintf(canalysis->result,"删除文件夹成功，当前目录为%s",canalysis->nowPath);

    mysql_free_result(rows);
    

    return 0;
}

//file类的返回应该为filename,直接用结构体的lastname读取了
int putsFile1(const char* finalPath,Canalysis_t* canalysis){
    DEBUG_PRINT("begin putsFile finalpath is %s\n",finalPath);
    bzero(canalysis->result,canalysis->resultLength);
    
    sprintf(canalysis->result,"%s",finalPath);

    return 0;
}

int getsFile1(const char* finalPath,Canalysis_t* canalysis){   
    DEBUG_PRINT("begin getsFile finalpath is %s\n",finalPath);
    bzero(canalysis->result,canalysis->resultLength);

    sprintf(canalysis->result,"%s",finalPath);

    return 0;
}

int removeFile(const char* finalPath,Canalysis_t* canalysis)
{   
    DEBUG_PRINT("begin removeFile finalpath is %s\n",finalPath);
    bzero(canalysis->result,canalysis->resultLength);
    
    char request[1024]={0};
    bzero(request,sizeof(request));
    sprintf(request,"select hash_sha1 from file_table where username = '%s' and type = 'f' and path = '%s'",
            canalysis->username,finalPath);

    int qret=mysql_query(canalysis->mysql,request);
    if(qret != 0){
        fprintf(stderr,"%s:%s\n","mysql_query",mysql_error(canalysis->mysql));
        DEBUG_PRINT("removeFile mysql_query failed\n");
        exit(-1);
    }
    MYSQL_RES* rows = mysql_store_result(canalysis->mysql);
    unsigned long rowNumber = mysql_num_rows(rows);
    if(rowNumber == 0){
        sprintf(canalysis->result,"该文件不存在！当前目录为：%s",canalysis->result);
        return -1;
    }

    MYSQL_ROW row = mysql_fetch_row(rows);
    char hashname[41];
    bzero(hashname,sizeof(hashname));
    sprintf(hashname,"%s",row[0]);

    sprintf(request,"delete from file_table where username = '%s' and type = 'f' and path = '%s'",canalysis->username,finalPath);
    qret=mysql_query(canalysis->mysql,request);
    if(qret != 0){
        fprintf(stderr,"%s:%s\n","mysql_query",mysql_error(canalysis->mysql));
        DEBUG_PRINT("pwdDir mysql_query failed\n");
        exit(-1);
    }

    mysql_free_result(rows);

    chdir(canalysis->absolutePath);
    remove(hashname);
        
    sprintf(canalysis->result,"该文件已删除！当前目录为：%s",canalysis->result);
    
    return 0;
}

//切割并压栈
int strtoken(char* command,dirStack_t* dstack){
    char* cname = NULL;
    char temp[1024];
    bzero(temp,sizeof(temp));
    strcpy(temp,command);

    char* p;
    p = strtok(temp,"/");
    while(p!=NULL){
        if(strcmp(p,"..")==0){
            if(dstack->stackElement == 0){
                p = strtok(NULL,"/");
                continue;
            }
            popDirStack(dstack,cname);
            free(cname);
            cname = NULL;
        }
        else if(strcmp(p,".")==0){

        }else{
            pushDirStack(dstack,p);
        }
        p = strtok(NULL,"/");
    };

    return 0;
}

//检z查路径是否正确
/* int checkPath(char* finalpath,Canalysis_t* canalysis){ */
    /* if(strlen(finalpath) < (unsigned long)canalysis->nowPathLength){ */
    /*     return -1; */
    /* } */
    /* int ret = strncmp(nowPath, anaCommand->absolutePath,anaCommand->homelength); */
    /* if(ret == 0){ */
    /*     return 0; */
    /* } */
    /* else{ */
    /*     return -1; */
    /* } */
/* } */

//遍历切割完成的栈并变成字符串路径
int concatenateString(dirStack_t* dstack,char* result){
    dirNode_t* current = dstack->top;
    char buffer[1024] = {0};
    while(current!=NULL){
        sprintf(result,"/%s%s",current->cname,buffer);
        
        DEBUG_PRINT("concatenateString current result is %s\n",result);

        strcpy(buffer,result);
        current = current->next;
    }
    return 0;
}


//worler的主调函数，传入一个字符串（总命令）concatenateString
//传入传出一个结构体，里面带有返回的字符串和对应的命令类型编号
int separationCommand(const char* command,Canalysis_t* canalysis){
    //函数指针，方便快速调用
    Funcptr funcArray[] = {cdDir,lsDir,pwdDir,mkDir,rmDir,getsFile1,putsFile1,removeFile};
    char tag[10] = {0};
    char identifier[1024] = {0};
    int ret = sscanf(command,"%s %s",tag,identifier);
    if(ret < 1){
        sprintf(canalysis->result,"读取出错");
        return -1;
    }
    printf("tag is %s\n",tag);
    printf("identifier is %s\n",identifier);
    /* if(identifier[0]=='\0'){ */
        /* printf("identifier is empty\n"); */
    /* } */
    chooseCommand(tag,canalysis);
    
    dirStack_t* dstack = initDirStack();
    
    strtoken(canalysis->nowPath,dstack);
    print_dirstack(dstack);

    strtoken(identifier,dstack);
    print_dirstack(dstack);
    DEBUG_PRINT("nowPath is %s\n",canalysis->nowPath);
    

    char finalPath[1024] = {0};
    if(dstack->stackElement == 0){
        sprintf(finalPath,"/");
    }
    else{
        concatenateString(dstack,finalPath);
    }
    DEBUG_PRINT("finalpath path is %s\n",finalPath);
    
    if(dstack->stackElement != 0){
        strcpy(canalysis->lastname,dstack->top->cname);
        DEBUG_PRINT("canalysis lastname is %s\n",canalysis->lastname);
    }
    else{
        sprintf(canalysis->lastname,"home");
        DEBUG_PRINT("canalysis lastname is %s\n",canalysis->lastname);
    }

    destoryDirStack(dstack);
    DEBUG_PRINT("after destoryDirStack\n");
    free(dstack);
    dstack = NULL;

    int result = funcArray[canalysis->flag - 1](finalPath,canalysis);
    if(result == -1){
        return -1;
    }
    DEBUG_PRINT("canalysis result is %s\n",canalysis->result);


    /* ret = checkPath(finalPath,canalysis); */
    /* if(ret == 0){ */
    /*     DEBUG_PRINT("路径正确\n"); */
        
    /*     int result = funcArray[canalysis->flag - 1](finalPath,canalysis); */
    /*     if(result == -1){ */
    /*         return -1; */
    /*     } */
    /*     DEBUG_PRINT("canalysis result is %s\n",canalysis->result); */
    /* } */
    /* else{ */
    /*     /1* bzero(canalysis->result,canalysis->resultLength); *1/ */
    /*     sprintf(canalysis->result,"不能超出用户空间"); */
    /*     DEBUG_PRINT("canalysis result is %s\n",canalysis->result); */
    /*     return -1; */     
    /* } */

    return 0;
}


//一键free，仅限初始化堆空间使用
int freeCanalysis(Canalysis_t* anaCommand){
    free(anaCommand->lastname);

    return 0;
}

//一键初始化，后续可更该里面的固定地址空间
int initCanalysis(Canalysis_t* canalysis){
    char findPWD[1024];
    bzero(findPWD,sizeof(findPWD));
    sprintf(findPWD,"select fid,path,filename from file_table where username = '%s' and parent_id = -1",canalysis->username);
    DEBUG_PRINT("findPWD is %s\n",findPWD);

    int qret = mysql_query(canalysis->mysql,findPWD);
    if(qret != 0){
        fprintf(stderr,"%s:%s\n","mysql_query",mysql_error(canalysis->mysql));
        exit(-1);
    }
    canalysis->resultLength = 1024;
    bzero(canalysis->result,canalysis->resultLength);
    MYSQL_RES* rows = mysql_store_result(canalysis->mysql);
    MYSQL_ROW row = mysql_fetch_row(rows);
    canalysis->pwd = atoi(row[0]);
    
    char absolutePathbuffer[1024];
    getcwd(absolutePathbuffer,sizeof(absolutePathbuffer));
    canalysis->absolutePathLength = 1024;
    sprintf(canalysis->absolutePath,"%s/user_dir",absolutePathbuffer);
    DEBUG_PRINT("absolutePath is %s\n",canalysis->absolutePath);

    canalysis->nowPathLength = 256;
    sprintf(canalysis->nowPath,"%s",row[1]);

    sprintf(canalysis->lastname,"%s",row[2]);

    DEBUG_PRINT("canalysis init complete, pwd is %d, nowPath is %s, lastname is %s\n",
                canalysis->pwd,canalysis->nowPath,canalysis->lastname);
    
    mysql_free_result(rows);

    return 0;
}

/* int main(){ */
/*     MYSQL* mysql = mysql_init(NULL); */
/*     MYSQL* ret = mysql_real_connect(mysql,"localhost","root","root","network_disk",0,NULL,0); */
/*     if(ret == NULL){ */
/*         fprintf(stderr,"%s:%s\n","mysql_real_connect",mysql_error(mysql)); */
/*         exit(-1); */
/*     } */
/*     Canalysis_t canalysis; */
/*     bzero(&canalysis,sizeof(canalysis)); */
/*     char name[] = "zhangsan"; */
/*     sprintf(canalysis.username,"%s",name); */
/*     DEBUG_PRINT("username is %s\n",canalysis.username); */
/*     canalysis.mysql = mysql; */
/*     DEBUG_PRINT("begin initCanalysis\n"); */
/*     initCanalysis(&canalysis); */
    
/*     DEBUG_PRINT("now path is %s,pwd is %d\n",canalysis.nowPath,canalysis.pwd); */
    
/*     separationCommand("mkdir dir1/dir2/dir3",&canalysis); */
    
/*     separationCommand("cd dir1/dir2/dir3",&canalysis); */
/*     DEBUG_PRINT("now path is %s,pwd is %d\n",canalysis.nowPath,canalysis.pwd); */
    
/*     separationCommand("cd ..",&canalysis); */
/*     DEBUG_PRINT("now path is %s,pwd is %d\n",canalysis.nowPath,canalysis.pwd); */
   
/*     DEBUG_PRINT("--------------------------\n"); */

/*     DEBUG_PRINT("now path is %s,pwd is %d\n",canalysis.nowPath,canalysis.pwd); */
/*     separationCommand("rmdir dir3",&canalysis); */
/*     DEBUG_PRINT("now path is %s,pwd is %d\n",canalysis.nowPath,canalysis.pwd); */
    
/*     DEBUG_PRINT("--------------------------\n"); */
/*     /1* separationCommand("cd dir1/dir2/dir3",&canalysis); *1/ */
/*     /1* separationCommand("rmdir dir3",&canalysis); *1/ */


/*     DEBUG_PRINT("--------------------------\n"); */
/*     separationCommand("mkdir dir4",&canalysis); */
/*     separationCommand("mkdir dir5",&canalysis); */
/*     separationCommand("mkdir dir6",&canalysis); */
/*     separationCommand("ls",&canalysis); */
/*     DEBUG_PRINT("result is %s\n",canalysis.result); */

/*     DEBUG_PRINT("--------------------------\n"); */
    


/*     separationCommand("cd ..",&canalysis); */
/*     DEBUG_PRINT("now path is %s,pwd is %d\n",canalysis.nowPath,canalysis.pwd); */

/*     separationCommand("cd ..",&canalysis); */
/*     DEBUG_PRINT("now path is %s,pwd is %d\n",canalysis.nowPath,canalysis.pwd); */

/*     return 0; */
/* } */



